package cn.sinata.wanglin.mine.activity;


import android.support.v7.widget.RecyclerView;

import com.xilada.xldutils.activitys.RecyclerListActivity;
import com.xilada.xldutils.utils.SharedPreferencesUtils;
import com.xilada.xldutils.view.SwipeRefreshRecyclerLayout;

import java.util.ArrayList;
import java.util.List;

import cn.sinata.wanglin.adapter.ShieldpersonAdapter;
import cn.sinata.wanglin.commonutils.Constant;
import cn.sinata.wanglin.model.Shieldperson;
import cn.sinata.wanglin.net.HttpManager;
import cn.sinata.wanglin.net.model.util.ResultDataSubscriber;

public class BlacklistActivity extends RecyclerListActivity {
    private ShieldpersonAdapter mShieldpersonAdapter;
    private List<Shieldperson> mShieldpersons = new ArrayList<>();
    @Override
    protected void initView() {
        super.initView();
        setTitle("黑名单管理");
        getData();
    }
    @Override
    protected SwipeRefreshRecyclerLayout.Mode getMode() {
        return SwipeRefreshRecyclerLayout.Mode.Top;
    }
    @Override
    protected RecyclerView.Adapter setAdapter() {
        mShieldpersonAdapter=new ShieldpersonAdapter(mShieldpersons,BlacklistActivity.this,1);
        return mShieldpersonAdapter;
    }

    @Override
    public void pullDownRefresh() {
        getData();
    }
    private void getData(){
        String userid= SharedPreferencesUtils.getString(Constant.SP_USERID);
        HttpManager.blackList(userid,1).subscribe(new ResultDataSubscriber<ArrayList<Shieldperson>>(this) {
            @Override
            public void onSuccess(String msg, ArrayList<Shieldperson> shieldpersons) {
                if(shieldpersons!=null){
                    mShieldpersons.clear();
                    mShieldpersons.addAll(shieldpersons);
                    mShieldpersonAdapter.notifyDataSetChanged();
                }
            }
        });
    }
}
